﻿using IdentityServer4.EntityFramework.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ZFY.UMC.Identity.Model.Api;
using ZFY.UMC.API.Model;

namespace ZFY.UMC.Identity.Controllers.Api
{
    public class ApiController : Controller
    {
        private readonly IConfigurationDbContext _dbContext;

        public ApiController(IConfigurationDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        [HttpGet]
        public async Task<IActionResult> Index(int pageIndex)
        {

            var apiList = (await _dbContext.ApiResources.Include(x => x.Properties).Skip((pageIndex - 1) * 8).ToListAsync()).Select(x => new ApiViewModel
            {

                ApiName = x.DisplayName,
                ApiUrl = x.Properties.FirstOrDefault(x => x.Key == "apiUrl")?.Value,
                LogoUrl = x.Properties.FirstOrDefault(x => x.Key == "logoUrl")?.Value
            }).ToList();

            return View(apiList);
        }
    }
}
